﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mindfor.Web.Features
{
	/// <summary>
	/// Types of entities used in text.
	/// </summary>
	public enum TypografEntityTypes
	{
		/// <summary>
		/// Html tags.
		/// </summary>
		HtmlEntities = 1,

		/// <summary>
		/// Xml tags.
		/// </summary>
		XmlEntities,

		/// <summary>
		/// Plain text - no special tags.
		/// </summary>
		NoEntities,

		/// <summary>
		/// Mixed.
		/// </summary>
		MixedEntities
	}

	/// <summary>
	/// Class for using artlebedev typograf web service.
	/// </summary>
	public static class Typograf
	{
		/// <summary>
		/// Processes text. If couldn't connect to remote typograf - returns initial passed text.
		/// </summary>
		/// <param name="text">Text to process with typograph. Can be html or not - see constructor parameters.</param>
		/// <param name="entityType">Type of entities.</param>
		/// <param name="useLineBreaks">Use line breakes (br html tag).</param>
		/// <param name="useParagraphs">Use paragraphs (p html tag).</param>
		/// <param name="maxNoBr">Maximum count of non-breaks.</param>
		/// <returns>Processed text. If couldn't connect to remote typograf - initial passed text.</returns>
		public static string ProcessText(string text, TypografEntityTypes entityType, bool useLineBreaks = false, bool useParagraphs = false, int maxNoBr = 3)
		{
			try
			{
				TypografProxy remoteTypograf = new TypografProxy();
				return remoteTypograf.ProcessText(text, (int)entityType, useLineBreaks, useParagraphs, maxNoBr);
			}
			catch
			{
				return text;
			}
		}
	}
}
